<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组排序</title>
</head>
<body>
    <script>
        //TODO: 字符串数组排序
        const stringArr = ["Joe", "Kapil", "Steve", "Musk"]
       const new1= stringArr.sort();
        console.log('%c   stringArr: new1','color: MidnightBlue; background: Aquamarine; font-size: 20px;', stringArr,new1);

        // 输出
        // (4) ["Joe", "Kapil", "Musk", "Steve"]

        const new2=  stringArr.reverse();
        // 输出
        // (4) ["Steve", "Musk", "Kapil", "Joe"]
        console.log('%c   stringArr:new2 ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', stringArr,new2);
        //TODO: 数字数组排序

        const array  = [40, 100, 1, 5, 25, 10];
        array.sort((a,b) => a-b);
        // 输出
        // (6) [1, 5, 10, 25, 40, 100]
        console.log('%c   array: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', array);

        array.sort((a,b) => b-a);
        // 输出
        // (6) [100, 40, 25, 10, 5, 1]
        console.log('%c   array: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', array);
        //TODO: 对象数组排序
        const objectArr = [
            { first_name: 'Lazslo', last_name: 'Jamf'     },
            { first_name: 'Pig',    last_name: 'Bodine'   },
            { first_name: 'Pirate', last_name: 'Prentice' }
        ];
        objectArr.sort((a, b) => a.last_name.localeCompare(b.last_name));
        console.log('%c   objectArr: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', objectArr);
        // 输出
        // (3) [{…}, {…}, {…}]
        // 0: {first_name: "Pig", last_name: "Bodine"}
        // 1: {first_name: "Lazslo", last_name: "Jamf"}
        // 2: {first_name: "Pirate", last_name: "Prentice"}
        length: 3

    </script>
</body>
</html>